import {
 request
} from '../request/request.js'

// 读取购物车数据
export function getread() {
 return new Promise((resolve, resject) => {
  wx.getStorage({
   key: "token",
   success(res) {
    request({
     url: `/shopping-cart/info?token=${res.data}`,
     method: 'GET',
    }).then(res => {
     resolve(res)
    })
   }
  })
 })
};


// 修改购物车状态
export function getupdata(obj) {
 return new Promise((resolve, resject) => {
  wx.getStorage({
   key: "token",
   success(res) {
    request({
     url: `/shopping-cart/select?token=${res.data}&&key=${obj.key}&&selected=${obj.selected}`,
     method: "POST",
    }).then(res => {
     resolve(res)
    })
   }
  })
 })
};

// 修改购物车购买数量
export function getnumbers(obj) {
 return new Promise((resolve, resject) => {
  wx.getStorage({
   key: "token",
   success(res) {
    request({
     url: `/shopping-cart/modifyNumber?token=${res.data}&&key=${obj.key}&&number=${obj.number}`,
     method: "POST",
    }).then(res => {
     resolve(res)
    })
   }
  })
 })
};

// 移除购物车中某条记录
export function getremove(obj) {
 return new Promise((resolve, resject) => {
  wx.getStorage({
   key: "token",
   success(res) {
    request({
     url: `/shopping-cart/remove?token=${res.data}&&key=${obj.key}`,
     method: "POST",
    }).then(res => {
     resolve(res)
    })
   }
  })
 })
};